package pers.vinsonws.jianghu.clientwin.ui;

import pers.vinsonws.jianghu.clientwin.global.Info;
import pers.vinsonws.jianghu.clientwin.service.ApplyChatRoomService;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @auther vinsonws
 * @date 2018/11/17 16:05
 */
public class NotJoinChatRoomUi extends JFrame {
    private static final long serialVersionUID = 5L;
    private JPanel mainPanel;                /*主面板*/
    private JLabel text;
    private JButton applyBtn;
    private JButton exitBtn;

    public NotJoinChatRoomUi(int chatRoomId, String chatRoomName) throws HeadlessException {
        setTitle("JH-江湖");
        //setLocation(220, 120);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        setUndecorated(false);
        mainPanel = new JPanel();
        mainPanel.setOpaque(false);
        mainPanel.setLayout(new BorderLayout());

        text = new JLabel();
        text.setText("你还未加入网络聊天室--" + chatRoomName);
        text.setFont(new Font("宋体", Font.BOLD, 30));
        text.setHorizontalAlignment(SwingConstants.CENTER);

        //
        applyBtn = new JButton("申请");
        applyBtn.setFont(new Font("宋体", Font.PLAIN, 16));
        applyBtn.setBounds(470, 370, 100, 40);
        applyBtn.setContentAreaFilled(false);
        mainPanel.add(applyBtn);

        //
        exitBtn = new JButton("退出");
        exitBtn.setFont(new Font("宋体", Font.PLAIN, 16));
        exitBtn.setBounds(600, 370, 100, 40);
        exitBtn.setContentAreaFilled(false);
        mainPanel.add(exitBtn);

        mainPanel.add(text);

        Info.tabbedPane.addTab(chatRoomName + "申请", mainPanel);

        applyBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //发送申请
                ApplyChatRoomService.sendApply(chatRoomId);
                //关闭
                Info.tabbedPane.remove(mainPanel);
                dispose();
            }
        });

        exitBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //关闭
                Info.tabbedPane.remove(mainPanel);
                dispose();
            }
        });
    }
}
